package com.flyan.game.motafx.core.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * 实体类型
 *
 * @author flyan
 * @version 1.0
 * @email flyan_by_chenu@sina.com
 * @since 2025/1/31
 */
@AllArgsConstructor
@Getter
public enum EntityTypeEnum {

    // ===================== 地形 =====================
    /* 空气墙 */
    TERRAIN_AIR_WALL("空气墙", EntityClassifyEnum.TERRAIN, -1, ZLayerEnum.MID),
    /* 地面 */
    TERRAIN_GROUND("地面", EntityClassifyEnum.TERRAIN, 0, ZLayerEnum.LOW),
    /* 草地 */
    TERRAIN_GRASS("草地", EntityClassifyEnum.TERRAIN, 1, ZLayerEnum.MID),
    /* 森林 */
    TERRAIN_FOREST("森林", EntityClassifyEnum.TERRAIN, 2, ZLayerEnum.HIGH),
    /* 墙 */
    TERRAIN_WALL("墙", EntityClassifyEnum.TERRAIN, 3, ZLayerEnum.MID),
    /* 暗墙 */
    TERRAIN_HIDDEN_WALL("暗墙", EntityClassifyEnum.TERRAIN, 4, ZLayerEnum.MID),
    /* 石墙 */
    TERRAIN_STONE_WALL("石墙", EntityClassifyEnum.TERRAIN, 13, ZLayerEnum.MID),
    /* 下楼梯 */
    TERRAIN_DOWN_STAIRS("下楼梯", EntityClassifyEnum.TERRAIN, 23, ZLayerEnum.LOW),
    /* 上楼梯 */
    TERRAIN_UP_STAIRS("上楼梯", EntityClassifyEnum.TERRAIN, 24, ZLayerEnum.LOW1),
    /* 黄门（普通门） */
    TERRAIN_DOOR("黄门（普通门）", EntityClassifyEnum.TERRAIN, 25, ZLayerEnum.MID),
    /* 蓝门 */
    TERRAIN_BLUE_DOOR("蓝门", EntityClassifyEnum.TERRAIN, 26, ZLayerEnum.MID),
    /* 红门 */
    TERRAIN_RED_DOOR("红门", EntityClassifyEnum.TERRAIN, 27, ZLayerEnum.MID),
    /* 绿门 */
    TERRAIN_GREEN_DOOR("绿门", EntityClassifyEnum.TERRAIN, 28, ZLayerEnum.MID),
    /* 机关门 */
    TERRAIN_GATE_DOOR("机关门", EntityClassifyEnum.TERRAIN, 29, ZLayerEnum.MID),
    /* 牢门 */
    TERRAIN_PRISON_DOOR("牢门", EntityClassifyEnum.TERRAIN, 30, ZLayerEnum.MID),
    /* 祭坛左 */
    TERRAIN_LEFT_ALTAR("祭坛左", EntityClassifyEnum.TERRAIN, 31, ZLayerEnum.MID),
    /* 祭坛右 */
    TERRAIN_RIGHT_ALTAR("祭坛右", EntityClassifyEnum.TERRAIN, 32, ZLayerEnum.MID),

    // ===================== 角色 =====================
    /* 勇士 */
    CHARACTER_BRAVE("勇士", EntityClassifyEnum.CHARACTER, 0, ZLayerEnum.MID1),

    // ===================== 怪物 =====================
    /* 绿史莱姆 */
    MONSTER_GREEN_SLIME("绿史莱姆", EntityClassifyEnum.MONSTER, 0, ZLayerEnum.MID),
    /* 红史莱姆 */
    MONSTER_RED_SLIME("红史莱姆", EntityClassifyEnum.MONSTER, 1, ZLayerEnum.MID),
    /* 黑史莱姆 */
    MONSTER_BLACK_SLIME("黑史莱姆", EntityClassifyEnum.MONSTER, 2, ZLayerEnum.MID),
    /* 史莱姆王 */
    MONSTER_SLIME_KING("史莱姆王", EntityClassifyEnum.MONSTER, 3, ZLayerEnum.MID),
    /* 小蝙蝠 */
    MONSTER_LITTLE_BAT("小蝙蝠", EntityClassifyEnum.MONSTER, 4, ZLayerEnum.MID),
    /* 大蝙蝠 */
    MONSTER_GIANT_BAT("大蝙蝠", EntityClassifyEnum.MONSTER, 5, ZLayerEnum.MID),
    /* 红蝙蝠 */
    MONSTER_RED_BAT("红蝙蝠", EntityClassifyEnum.MONSTER, 6, ZLayerEnum.MID),
    /* 吸血鬼 */
    MONSTER_VAMPIRE("吸血鬼", EntityClassifyEnum.MONSTER, 7, ZLayerEnum.MID),
    /* 骷髅人 */
    MONSTER_SKELETON_MAN("骷髅人", EntityClassifyEnum.MONSTER, 8, ZLayerEnum.MID),
    /* 骷髅士兵 */
    MONSTER_SKELETON_SOLDIER("骷髅士兵", EntityClassifyEnum.MONSTER, 9, ZLayerEnum.MID),
    /* 骷髅队长 */
    MONSTER_SKELETON_CAPTAIN("骷髅队长", EntityClassifyEnum.MONSTER, 10, ZLayerEnum.MID),
    /* 死灵战士 */
    MONSTER_GHOST_SOLDIER("死灵战士", EntityClassifyEnum.MONSTER, 11, ZLayerEnum.MID),
    /* 丧尸（兽人） */
    MONSTER_ZOMBIE("丧尸", EntityClassifyEnum.MONSTER, 12, ZLayerEnum.MID),
    /* 丧尸骑士（兽人武士） */
    MONSTER_ZOMBIE_KNIGHT("丧尸", EntityClassifyEnum.MONSTER, 13, ZLayerEnum.MID),
    /* 石怪 */
    ROCK("石怪", EntityClassifyEnum.MONSTER, 14, ZLayerEnum.MID),
    /* 史莱姆人 */
    MONSTER_SLIME_MAN("史莱姆人", EntityClassifyEnum.MONSTER, 15, ZLayerEnum.MID),
    /* 初级法师 */
    MONSTER_JUNIOR_MAGE("初级法师", EntityClassifyEnum.MONSTER, 16, ZLayerEnum.MID),
    /* 高级法师 */
    MONSTER_SENIOR_MAGE("高级法师", EntityClassifyEnum.MONSTER, 17, ZLayerEnum.MID),
    /* 初级魔术士 */
    MONSTER_JUNIOR_MAGICIAN("初级魔术士", EntityClassifyEnum.MONSTER, 18, ZLayerEnum.MID),
    /* 高级魔术士 */
    MONSTER_SENIOR_MAGICIAN("高级魔术士", EntityClassifyEnum.MONSTER, 19, ZLayerEnum.MID),
    /* 初级门卫 */
    MONSTER_GATE_KEEPER_C("初级门卫", EntityClassifyEnum.MONSTER, 20, ZLayerEnum.MID),
    /* 中级门卫 */
    MONSTER_GATE_KEEPER_B("中级门卫", EntityClassifyEnum.MONSTER, 21, ZLayerEnum.MID),
    /* 高级门卫 */
    MONSTER_GATE_KEEPER_A("高级门卫", EntityClassifyEnum.MONSTER, 22, ZLayerEnum.MID),
    /* 双手剑士 */
    MONSTER_TWO_HANDED_SWORDSMAN("双手剑士", EntityClassifyEnum.MONSTER, 23, ZLayerEnum.MID),
    /* 战士 */
    MONSTER_SOLDIER("战士", EntityClassifyEnum.MONSTER, 24, ZLayerEnum.MID),
    /* 金骑士（骑士队长） */
    MONSTER_GOLDEN_KNIGHT("金骑士", EntityClassifyEnum.MONSTER, 25, ZLayerEnum.MID),
    /* 骑士 */
    MONSTER_KNIGHT("骑士", EntityClassifyEnum.MONSTER, 26, ZLayerEnum.MID),
    /* 黑骑士 */
    MONSTER_DARK_KNIGHT("黑骑士", EntityClassifyEnum.MONSTER, 27, ZLayerEnum.MID),
    /* 黄衣芝诺 */
    MONSTER_YELLOW_ZENO("黄衣芝诺", EntityClassifyEnum.MONSTER, 29, ZLayerEnum.MID),
    /* 绿魔导师 */
    MONSTER_GREEN_MAGIC_SERGEANT("魔导师", EntityClassifyEnum.MONSTER, 30, ZLayerEnum.MID),
    /* 红衣芝诺 */
    MONSTER_RED_ZENO("红衣芝诺", EntityClassifyEnum.MONSTER, 44, ZLayerEnum.MID),
    /* 魔导师 */
    MONSTER_MAGIC_SERGEANT("魔导师", EntityClassifyEnum.MONSTER, 45, ZLayerEnum.MID),
    /* 大魔导师 */
    MONSTER_GREAT_MAGIC_SERGEANT("大魔导师", EntityClassifyEnum.MONSTER, 46, ZLayerEnum.MID),

    // ===================== 物品 =====================
    /* 黄钥匙 */
    ITEM_KEY("黄钥匙", EntityClassifyEnum.ITEM, 0, ZLayerEnum.MID),
    /* 蓝钥匙 */
    ITEM_BLUE_KEY("蓝钥匙", EntityClassifyEnum.ITEM, 1, ZLayerEnum.MID),
    /* 红钥匙 */
    ITEM_RED_KEY("红钥匙", EntityClassifyEnum.ITEM, 2, ZLayerEnum.MID),
    /* 绿钥匙 */
    ITEM_GREEN_KEY("绿钥匙", EntityClassifyEnum.ITEM, 3, ZLayerEnum.MID),
    /* 魔法钥匙 */
    ITEM_MAGIC_KEY("魔法钥匙", EntityClassifyEnum.ITEM, 6, ZLayerEnum.MID),
    /* 怪物手册 */
    ITEM_MONSTER_MANUAL("怪物手册", EntityClassifyEnum.ITEM, 9, ZLayerEnum.MID),
    /* 记事本 */
    ITEM_NOTEBOOK("记事本", EntityClassifyEnum.ITEM, 10, ZLayerEnum.MID),
    /* 幸运金币 */
    ITEM_LUCKY_GOLD("幸运金币", EntityClassifyEnum.ITEM, 11, ZLayerEnum.MID),
    /* 楼层传送器 */
    ITEM_FLOOR_CONVEYOR("楼层传送器", EntityClassifyEnum.ITEM, 12, ZLayerEnum.MID),
    /* 红宝石 */
    ITEM_RED_GEM("红宝石", EntityClassifyEnum.ITEM, 16, ZLayerEnum.MID),
    /* 蓝宝石 */
    ITEM_BLUE_GEM("蓝宝石", EntityClassifyEnum.ITEM, 17, ZLayerEnum.MID),
    /* 红血瓶 */
    ITEM_RED_POTION("红血瓶", EntityClassifyEnum.ITEM, 20, ZLayerEnum.MID),
    /* 蓝血瓶 */
    ITEM_BLUE_POTION("蓝血瓶", EntityClassifyEnum.ITEM, 21, ZLayerEnum.MID),
    /* 勇者灵球 */
    ITEM_ORB_HERO("勇者灵球", EntityClassifyEnum.ITEM, 30, ZLayerEnum.MID),
    /* 智慧灵球 */
    ITEM_ORB_WISDOM("智慧灵球", EntityClassifyEnum.ITEM, 31, ZLayerEnum.MID),
    /* 铁剑 */
    ITEM_IRON_SWORD("铁剑", EntityClassifyEnum.ITEM, 50, ZLayerEnum.MID),
    /* 银剑 */
    ITEM_SILVER_SWORD("银剑", EntityClassifyEnum.ITEM, 51, ZLayerEnum.MID),
    /* 骑士剑 */
    ITEM_KNIGHT_SWORD("骑士剑", EntityClassifyEnum.ITEM, 52, ZLayerEnum.MID),
    /* 圣剑 */
    ITEM_HOLY_SWORD("圣剑", EntityClassifyEnum.ITEM, 53, ZLayerEnum.MID),
    /* 神圣剑 */
    ITEM_DIVINE_SWORD("神圣剑", EntityClassifyEnum.ITEM, 54, ZLayerEnum.MID),
    /* 铁盾 */
    ITEM_IRON_SHIELD("铁盾", EntityClassifyEnum.ITEM, 55, ZLayerEnum.MID),
    /* 银盾 */
    ITEM_SILVER_SHIELD("银盾", EntityClassifyEnum.ITEM, 56, ZLayerEnum.MID),
    /* 骑士盾 */
    ITEM_KNIGHT_SHIELD("骑士盾", EntityClassifyEnum.ITEM, 57, ZLayerEnum.MID),
    /* 圣盾 */
    ITEM_HOLY_SHIELD("圣盾", EntityClassifyEnum.ITEM, 58, ZLayerEnum.MID),
    /* 神圣盾 */
    ITEM_DIVINE_SHIELD("神圣盾", EntityClassifyEnum.ITEM, 59, ZLayerEnum.MID),

    // ===================== NPC =====================
    /* 老人 */
    NPC_ELDERLY("老人", EntityClassifyEnum.NPC, 0, ZLayerEnum.MID),
    /* 商人 */
    NPC_MERCHANT("商人", EntityClassifyEnum.NPC, 1, ZLayerEnum.MID),
    /* 盗贼 */
    NPC_THIEF("盗贼", EntityClassifyEnum.NPC, 2, ZLayerEnum.MID),
    /* 红祭坛 */
    NPC_RED_ALTAR("红祭坛", EntityClassifyEnum.NPC, 9, ZLayerEnum.MID),
    /* 蓝祭坛 */
    NPC_BLUE_ALTAR("蓝祭坛", EntityClassifyEnum.NPC, 10, ZLayerEnum.MID),
    /* 公主 */
    NPC_PRINCESS("公主", EntityClassifyEnum.NPC, 11, ZLayerEnum.MID),

    // ===================== 动画 =====================
    /* 攻击动画 */
    ANIMATE_ATTACK("", EntityClassifyEnum.ANIMATE, 0, ZLayerEnum.MID),

    ;

    /**
     * 实体类型名称
     */
    private final String name;
    /**
     * 分类
     */
    private final EntityClassifyEnum classify;
    /**
     * 类型编码
     */
    private final Integer type;
    /**
     * z轴图层索引
     */
    private final ZLayerEnum zIndex;

    /**
     * 唯一标识编号，懒加载
     */
    private Integer code;

    EntityTypeEnum(String name, EntityClassifyEnum classify, Integer type, ZLayerEnum zIndex) {
        this.name = name;
        this.classify = classify;
        this.type = type;
        this.zIndex = zIndex;
    }

    public static List<EntityTypeEnum> getByClassify(EntityClassifyEnum classify) {
        List<EntityTypeEnum> list = new ArrayList<>();
        for (EntityTypeEnum e : values()) {
            if (e.getClassify() == classify) {
                list.add(e);
            }
        }
        return list;
    }

    /**
     * @return 实体编号，其等于：分类编码 * 1000 + 类型编码，若是正数，再+1
     */
    public int getCode() {
        if (code != null) {
            return code;
        }
        code = classify.getCode() * 1000 + type;
        if (code >= 0) {
            code += 1;
        }
        return code;
    }

    /**
     * 通过实体编号获取实体枚举
     *
     * @param code 实体编号
     * @return 枚举
     */
    public static EntityTypeEnum valueOfCode(int code) {
        for (EntityTypeEnum e : values()) {
            if (e.getCode() == code) {
                return e;
            }
        }
        return null;
    }

}
